using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Collisions;
using Microsoft.Xna.Framework;

namespace StupidSpaceThing
{
	// only support square display so far ...
	internal class ColRect : ColObject
	{
		private Quad quad;
		public readonly float Width;
		public readonly float HalfWidth;
		public readonly float Height;
		public readonly float HalfHeight;
		
		public ColRect(Entity entity, float mass, float width, float height)
			: base(entity, BodyFactory.Instance.CreateRectangleBody(Game1.Simulator, width, height, mass)) {
			this.geom = GeomFactory.Instance.CreateRectangleGeom(Game1.Simulator, Body, width, height);			
			if( Game1.GenCollisionObjects ) {
				quad = new Quad(Game1.RectangleTexture);
			}
			this.Width = width;
			this.HalfWidth = width / 2;
			this.Height = height;
			this.HalfHeight = height / 2;
		}

		public override bool Within(Vector2 point) {
			if( point.X > entity.Position2D.X - HalfWidth && point.X < entity.Position2D.X + HalfWidth &&
				point.Y > entity.Position2D.Y - HalfHeight && point.Y < entity.Position2D.Y + HalfHeight ) {
				return true;
			}
			return false;
		}

		public override void Draw(Camera camera) {
			quad.Color = Color;
			quad.Position = Position;
			quad.Scale = HalfWidth;
			quad.Draw(camera);
		}
	}
}
